﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace TEL.ClientClasses.Public
{
    public class WaitSecond
    {
        public event EventHandler WaitEvent;
        public int Seconds { get; private set; }
        private readonly object SendData = null;

        public WaitSecond(int seconds, object data)
        {
            Seconds = seconds;
            SendData = data;

            Task.Factory.StartNew(Wait);
        }
        private void Wait()
        {
            AutoResetEvent wait = new AutoResetEvent(false);
            TimeSpan ts = DateTime.Now.AddSeconds(Seconds) - DateTime.Now;
          
            wait.WaitOne(ts);
            if (WaitEvent != null) WaitEvent(SendData, EventArgs.Empty);

        }
    }
}
